﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DoctorReg
{
    public partial class FormPacientes : Form
    {
        public FormPacientes()
        {
            InitializeComponent();
        }

        private void FormPacientes_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoSizeColumnsMode =
   DataGridViewAutoSizeColumnsMode.AllCells;
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.AllowUserToDeleteRows = false;
            dataGridView1.EditMode =
            DataGridViewEditMode.EditProgrammatically;
            ConsultasDataSetTableAdapters.PacientesTableAdapter
            adapterPacientes = new
            ConsultasDataSetTableAdapters.PacientesTableAdapter();
            ConsultasDataSet.PacientesDataTable tabPacientes = new
            ConsultasDataSet.PacientesDataTable();
            adapterPacientes.Fill(tabPacientes);
            foreach (DataColumn coluna in tabPacientes.Columns)
            {
                dataGridView1.Columns.Add(coluna.ColumnName,
                coluna.ColumnName);
            }
            int idxLinha = 0, idxColuna = 0;
            foreach (DataRow linha in tabPacientes.Rows)
            {
                DataGridViewRow linhaDataGrid = new DataGridViewRow();
                dataGridView1.Rows.Add(linhaDataGrid);
                foreach (DataColumn coluna in tabPacientes.Columns)
                {
                    if (idxColuna == 4)
                    {
                        DateTime data = (DateTime)
                        tabPacientes.Rows[idxLinha][idxColuna];
                        dataGridView1.Rows[idxLinha].Cells[idxColuna].Value =
                        data.ToShortDateString();
                    }
                    else
                    {
                        dataGridView1.Rows[idxLinha].Cells[idxColuna].Value =
                        tabPacientes.Rows[idxLinha][idxColuna];
                    }
                    idxColuna = idxColuna + 1;
                }
                idxLinha = idxLinha + 1;
                idxColuna = 0;
            }

        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int codigo;
            string nome, distrito, sexo;
            DateTime dn;
            codigo = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;
            nome =
            dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
            distrito =
            dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            sexo =
            dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
            dn = Convert.ToDateTime(dataGridView1.Rows[e.RowIndex].Cells[4].Value);
            FormPacientes2 form = new FormPacientes2();
            form.Alterar(codigo, nome, distrito, sexo, dn);
            form.ShowDialog();

        }
    }
}
